//
//  Hashtable.h
//  Symbol Table
//
//  Created by Pei Liu on 10/4/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#ifndef Symbol_Table_Hashtable_h
#define Symbol_Table_Hashtable_h

#include<stdlib.h>

typedef size_t hash_size;

//type of ENTRY
typedef struct hashnode 
{
	char *name;
	char *type;
    int size;
    int location;
	struct hashnode *next;
}ENTRY;

//type of symbol table
typedef struct hashtbl 
{
	hash_size size;
	ENTRY** nodes;
	hash_size (*hashfunc)(const char *);
} HASHTBL;

//create hash function
HASHTBL* hashtbl_create(hash_size size, hash_size (*hashfunc)(const char *));
//release the hash table
void hashtbl_destroy(HASHTBL *hashtbl);
//insert into the table
int hashtbl_insert(HASHTBL* hashtbl, const char *name, const char *type, int size, int location);
//remove items from table
int hashtbl_remove(HASHTBL* hashtbl, const char *name);
//Lookup function
ENTRY* hashtbl_get(HASHTBL* hashtbl, const char *name);
//resize the symbol table
int hashtbl_resize(HASHTBL* hashtbl, hash_size size);
//print an entry
void PrintEntry(ENTRY* node);
//Table traversal
void hashtbl_trav(HASHTBL* hashtable);
#endif
